package leetcode.stack;

import java.util.Stack;

/**
 * @Description: https://leetcode.cn/problems/min-stack/
 * @Author Ammar
 * @Create 2023/7/11 14:40
 */
public class _155_最小栈_链表 {
    Stack<Integer> stack;
    Stack<Integer> minStack;

    public _155_最小栈_链表() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if (!minStack.empty()) minStack.push(Math.min(getMin(), val));
        else minStack.push(val);
    }

    public void pop() {
        stack.pop();
        minStack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
